/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 *
 * $Id$
 */
package org.sgt.datamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.sgt.datamodel.Action;
import org.sgt.datamodel.ActionSpecification;
import org.sgt.datamodel.Container;
import org.sgt.datamodel.DataStore;
import org.sgt.datamodel.DatamodelPackage;
import org.sgt.datamodel.Value;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Container</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getLocalPackages <em>Local Packages</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getReferencedPackages <em>Referenced Packages</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getActionSpecifications <em>Action Specifications</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getActions <em>Actions</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getValues <em>Values</em>}</li>
 *   <li>{@link org.sgt.datamodel.impl.ContainerImpl#getDataStore <em>Data Store</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ContainerImpl extends ENamedElementImpl implements Container {
	/**
	 * The cached value of the '{@link #getLocalPackages() <em>Local Packages</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalPackages()
	 * @generated
	 * @ordered
	 */
	protected EList<EPackage> localPackages;

	/**
	 * The cached value of the '{@link #getReferencedPackages() <em>Referenced Packages</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferencedPackages()
	 * @generated
	 * @ordered
	 */
	protected EList<EPackage> referencedPackages;

	/**
	 * The cached value of the '{@link #getActionSpecifications() <em>Action Specifications</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getActionSpecifications()
	 * @generated
	 * @ordered
	 */
	protected EList<ActionSpecification> actionSpecifications;

	/**
	 * The cached value of the '{@link #getActions() <em>Actions</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getActions()
	 * @generated
	 * @ordered
	 */
	protected EList<Action> actions;

	/**
	 * The cached value of the '{@link #getValues() <em>Values</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValues()
	 * @generated
	 * @ordered
	 */
	protected EList<Value> values;

	/**
	 * The cached value of the '{@link #getDataStore() <em>Data Store</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataStore()
	 * @generated
	 * @ordered
	 */
	protected DataStore dataStore;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ContainerImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DatamodelPackage.Literals.CONTAINER;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EPackage> getLocalPackages() {
		if (localPackages == null) {
			localPackages = new EObjectContainmentEList<EPackage>(EPackage.class, this, DatamodelPackage.CONTAINER__LOCAL_PACKAGES);
		}
		return localPackages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EPackage> getReferencedPackages() {
		if (referencedPackages == null) {
			referencedPackages = new EObjectResolvingEList<EPackage>(EPackage.class, this, DatamodelPackage.CONTAINER__REFERENCED_PACKAGES);
		}
		return referencedPackages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ActionSpecification> getActionSpecifications() {
		if (actionSpecifications == null) {
			actionSpecifications = new EObjectContainmentEList<ActionSpecification>(ActionSpecification.class, this, DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS);
		}
		return actionSpecifications;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Action> getActions() {
		if (actions == null) {
			actions = new EObjectContainmentEList<Action>(Action.class, this, DatamodelPackage.CONTAINER__ACTIONS);
		}
		return actions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Value> getValues() {
		if (values == null) {
			values = new EObjectContainmentEList<Value>(Value.class, this, DatamodelPackage.CONTAINER__VALUES);
		}
		return values;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DataStore getDataStore() {
		return dataStore;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDataStore(DataStore newDataStore, NotificationChain msgs) {
		DataStore oldDataStore = dataStore;
		dataStore = newDataStore;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DatamodelPackage.CONTAINER__DATA_STORE, oldDataStore, newDataStore);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDataStore(DataStore newDataStore) {
		if (newDataStore != dataStore) {
			NotificationChain msgs = null;
			if (dataStore != null)
				msgs = ((InternalEObject)dataStore).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DatamodelPackage.CONTAINER__DATA_STORE, null, msgs);
			if (newDataStore != null)
				msgs = ((InternalEObject)newDataStore).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DatamodelPackage.CONTAINER__DATA_STORE, null, msgs);
			msgs = basicSetDataStore(newDataStore, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatamodelPackage.CONTAINER__DATA_STORE, newDataStore, newDataStore));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DatamodelPackage.CONTAINER__LOCAL_PACKAGES:
				return ((InternalEList<?>)getLocalPackages()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS:
				return ((InternalEList<?>)getActionSpecifications()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.CONTAINER__ACTIONS:
				return ((InternalEList<?>)getActions()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.CONTAINER__VALUES:
				return ((InternalEList<?>)getValues()).basicRemove(otherEnd, msgs);
			case DatamodelPackage.CONTAINER__DATA_STORE:
				return basicSetDataStore(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DatamodelPackage.CONTAINER__LOCAL_PACKAGES:
				return getLocalPackages();
			case DatamodelPackage.CONTAINER__REFERENCED_PACKAGES:
				return getReferencedPackages();
			case DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS:
				return getActionSpecifications();
			case DatamodelPackage.CONTAINER__ACTIONS:
				return getActions();
			case DatamodelPackage.CONTAINER__VALUES:
				return getValues();
			case DatamodelPackage.CONTAINER__DATA_STORE:
				return getDataStore();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DatamodelPackage.CONTAINER__LOCAL_PACKAGES:
				getLocalPackages().clear();
				getLocalPackages().addAll((Collection<? extends EPackage>)newValue);
				return;
			case DatamodelPackage.CONTAINER__REFERENCED_PACKAGES:
				getReferencedPackages().clear();
				getReferencedPackages().addAll((Collection<? extends EPackage>)newValue);
				return;
			case DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS:
				getActionSpecifications().clear();
				getActionSpecifications().addAll((Collection<? extends ActionSpecification>)newValue);
				return;
			case DatamodelPackage.CONTAINER__ACTIONS:
				getActions().clear();
				getActions().addAll((Collection<? extends Action>)newValue);
				return;
			case DatamodelPackage.CONTAINER__VALUES:
				getValues().clear();
				getValues().addAll((Collection<? extends Value>)newValue);
				return;
			case DatamodelPackage.CONTAINER__DATA_STORE:
				setDataStore((DataStore)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DatamodelPackage.CONTAINER__LOCAL_PACKAGES:
				getLocalPackages().clear();
				return;
			case DatamodelPackage.CONTAINER__REFERENCED_PACKAGES:
				getReferencedPackages().clear();
				return;
			case DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS:
				getActionSpecifications().clear();
				return;
			case DatamodelPackage.CONTAINER__ACTIONS:
				getActions().clear();
				return;
			case DatamodelPackage.CONTAINER__VALUES:
				getValues().clear();
				return;
			case DatamodelPackage.CONTAINER__DATA_STORE:
				setDataStore((DataStore)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DatamodelPackage.CONTAINER__LOCAL_PACKAGES:
				return localPackages != null && !localPackages.isEmpty();
			case DatamodelPackage.CONTAINER__REFERENCED_PACKAGES:
				return referencedPackages != null && !referencedPackages.isEmpty();
			case DatamodelPackage.CONTAINER__ACTION_SPECIFICATIONS:
				return actionSpecifications != null && !actionSpecifications.isEmpty();
			case DatamodelPackage.CONTAINER__ACTIONS:
				return actions != null && !actions.isEmpty();
			case DatamodelPackage.CONTAINER__VALUES:
				return values != null && !values.isEmpty();
			case DatamodelPackage.CONTAINER__DATA_STORE:
				return dataStore != null;
		}
		return super.eIsSet(featureID);
	}

} //ContainerImpl
